<?php
namespace Common\Model;

use Api\Model\JobsInfoModel;
use Think\Model;

class OrderModel extends Model {
    public $order_type = array(1 => '套餐升级', 2 => '充值积分', 3 => '简历置顶', 4 => '醒目标签', 5 => '简历模板', 6 => '简历包', 7 => '短信包', 8 => '职位置顶', 9 => '职位紧急', 10 => '企业模板', 11 => '诚聘通', 12 => '预约刷新职位', 13 => '职位刷新', 14 => '简历下载',15=>'工程币',16=>'发布职位', 17=>'求职变更人才顾问', 18=>'投递简历',19=>'赠送套餐',20=>'赠送工程币');
    protected $_validate = array(
        array('uid,oid,utype,order_type,pay_type,payment,payment_cn,service_name,description', 'identicalNull', '', 1, 'callback'),
        array('uid,utype,order_type,pay_type', 'identicalEnum', '', 0, 'callback'),
    );
    protected $_auto = array(
        array('is_paid', 1),
        array('addtime', 'time', 1, 'function'),
        array('fee', 0, 1)
    );

    /*
        获取单条订单信息
        @data 数组
    */
    public function get_order_one($data) {
        $info = $this->where($data)->find();
        if ($info['params']) {
            $info['params'] = unserialize($info['params']);
        }
        return $info;
    }

    public function edit_order($id, $uid, $is_paid, $pay_amount = 0, $pay_points = 0, $payment = '', $payment_cn = '', $description = '', $payment_time = 0) {
        if ($pay_amount > 0 && $pay_points > 0) {
            $setsqlarr['pay_type'] = 3;
        } elseif ($pay_amount > 0) {
            $setsqlarr['pay_type'] = 2;
        } else {
            $setsqlarr['pay_type'] = 1;
        }
        $setsqlarr['is_paid'] = $is_paid;
        $setsqlarr['pay_amount'] = $pay_amount;
        $setsqlarr['pay_points'] = $pay_points;
        $setsqlarr['payment'] = $payment;
        $setsqlarr['payment_cn'] = $payment_cn;
        $setsqlarr['description'] = $description;
        $setsqlarr['payment_time'] = $payment_time;
        $this->where(array('id' => $id, 'uid' => $uid))->save($setsqlarr);
    }

    /**
     * 添加订单数据
     * @param $user           用户信息
     * @param $oid            订单号
     * @param $order_type     订单类型，详见D('Order')->order_type
     * @param $amount         总金额
     * @param $pay_amount     现金支付金额
     * @param $pay_points     积分支付数
     * @param $service_name   所购买服务名称
     * @param $payment        支付方式英文
     * @param $payment_cn     支付方式中文
     * @param $description    订单详情描述
     * @param $addtime      下单时间
     * @param $is_paid 1待支付 2已支付
     * @param $points         购买积分数
     * @param $setmeal        购买套餐/增值服务id
     * @param $payment_time   支付时间
     * @param $params         需要特殊处理的参数序列化
     * @param $notes          备注
     * @param $job_id          职位id
     * @param $fa_type          职位发布类型
     */
    public function  add_order($user, $oid, $order_type, $amount, $pay_amount, $pay_points, $service_name, $payment, $payment_cn, $description, $addtime, $is_paid = 1, $points = 0.0, $setmeal = 0, $payment_time = 0, $params = '', $discount = '', $notes = '',$pay_gift=0.0,$gift_id=0,$job_id=0,$fa_type=0) {///************chm----start******       ,$pay_gift        ****/
        $info=unserialize($params);
        $uid = $user['uid'];
        $setsqlarr['oid'] = $oid;
        $setsqlarr['uid'] = $uid;
        $setsqlarr['jobs_id'] = $job_id;
        $setsqlarr['utype'] = $user['utype'];
        $setsqlarr['fa_type']=!empty($info['fa_type']) ? $info['fa_type'] : $fa_type;
        $setsqlarr['order_type'] = $order_type;
        if ($pay_amount > 0 && $pay_points > 0 && $pay_gift > 0) {
            $setsqlarr['pay_type'] = 7;//现金+积分+优惠券
        } elseif($pay_gift > 0 && $pay_points > 0) {
            $setsqlarr['pay_type'] = 6;//积分+优惠券
        } elseif($pay_amount > 0 && $pay_gift > 0) {
            $setsqlarr['pay_type'] = 5;//现金+优惠券
        } elseif($pay_amount > 0 && $pay_points > 0) {
            $setsqlarr['pay_type'] = 3;//现金+积分
        } elseif ($pay_amount > 0) {
            $setsqlarr['pay_type'] = 2;//现金
        } elseif ($pay_gift > 0) {
            $setsqlarr['pay_type'] = 4;//优惠券
        } elseif ($pay_points > 0) {
            $setsqlarr['pay_type'] = 1;//积分
        }
        $info=unserialize($params);

        $setsqlarr['is_paid'] = $is_paid;
        $setsqlarr['amount'] = $amount;
        $setsqlarr['pay_amount'] = $pay_amount;
        $setsqlarr['pay_points'] = $pay_points;
        $setsqlarr['pay_gift'] = $pay_gift?:0;
        $setsqlarr['gift_id'] = $gift_id?:0;
        $gift_issue_info=M("GiftIssue")->where(array("id"=>$gift_id))->find();
        $gift_issue_info['gift_info']=M("Gift")->where(array("id"=>$gift_issue_info['gift_id']))->find();
        if($gift_issue_info['gift_type']==1){
            $gift_pay_name="专享优惠券";
        }elseif($gift_issue_info['gift_type']==2){
            $gift_pay_name="新用户专享券";
        }elseif($gift_issue_info['gift_type']==3){
            $gift_pay_name="活动专享券";
        }

        $setsqlarr['payment'] = $payment;
        $setsqlarr['payment_cn'] = $payment_cn;
        $setsqlarr['description'] = $description;
        $setsqlarr['service_name'] = $service_name;
        $setsqlarr['points'] = $points;
        $setsqlarr['setmeal'] = !empty($info['setmeal_id']) ? $info['setmeal_id'] : $setmeal;
        $setsqlarr['params'] = $params;
        $setsqlarr['notes'] = $notes;
        $setsqlarr['addtime'] = $addtime;
        $setsqlarr['payment_time'] = $payment_time;
        $setsqlarr['discount'] = $discount;
        $setsqlarr['rid']=empty($info['resume_id']) ? 0 : $info['resume_id'];
        $setsqlarr['jobs_id']=empty($info['jobs_id']) ? $job_id : $info['jobs_id'];
        $payment_model = D('Payment')->where(array('typename' => $payment))->find();
        if ($payment_model && $pay_amount > 0) {
            $setsqlarr['fee'] = $pay_amount * $payment_model['fee'] / 100;
        } else {
            $setsqlarr['fee'] = 0;
        }
      //  var_dump(22);die;
      //  if (false === $this->create($setsqlarr)) return false;
        $insert_id = $this->add($setsqlarr);
      //  var_dump($setsqlarr);
      //  var_dump($this->getLastSql());die;
        $userinfo = M('Members')->where(array('uid' => $uid))->find();
        if (false === $sms = F('sms_config')) $sms = D('SmsConfig')->config_cache();
        if ($is_paid == 1) {
            if($user['utype']==1){
                if(C('qscms_site_dir')=='/'){
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }else{
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }
            }else{
                if(C('qscms_site_dir')=='/'){
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }else{
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }
            }
            $pms_message = '订单' . $oid . '已经添加成功，付款方式为：' . $payment_cn . '，应付金额' . $pay_amount . ($pay_points > 0 ? ('(抵扣' . $pay_points . C('qscms_points_byname') . ')') : '')  . ($pay_gift > 0 ? ('('.$gift_pay_name.'抵扣' . $pay_gift. '元)') : '') .  '。<a href="' . $replac_mail['order_url'] . '" target="_blank">点击查看详情>></a>';
            //发送站内信
            D('Pms')->write_pmsnotice($user['uid'], $user['username'], $pms_message,$user['utype']);
            //sms
            if ($sms['set_order'] == "1" && $amount > 0) {
                $sendSms['mobile'] = $user['mobile'];
                $sendSms['tpl'] = 'set_order';
                $sendSms['data'] = array('sitename' => C('qscms_site_name'), 'sitedomain' => C('qscms_site_name'), 'paymenttpye' => $payment_cn, 'oid' => $oid, 'amount' => $amount . '');
                //D('Sms')->sendSms('notice', $sendSms);
            }
            //微信
            if (C('apply.Weixin')) {
                D('Weixin/TplMsg')->add_order($setsqlarr['uid'], $setsqlarr['oid'], $setsqlarr['description'], $setsqlarr['amount']);
            }
        } else if ($is_paid == 2) {
            if($user['utype']==1){
                if(C('qscms_site_dir')=='/'){
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }else{
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }
            }else{
                if(C('qscms_site_dir')=='/'){
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }else{
                    $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }
            }
            $pms_message = '订单' . $oid . '已经支付成功，付款方式为：' . $payment_cn . '，支付金额' . $pay_amount . ($pay_points > 0 ? ('(抵扣' . $pay_points . C('qscms_points_byname') . ')') : '') . ($pay_gift > 0 ? ('('.$gift_pay_name.'抵扣' . $pay_gift. '元)') : '') .  '。<a href="' . $replac_mail['order_url'] . '" target="_blank">点击查看详情>></a>';
            //发送站内信
            D('Pms')->write_pmsnotice($user['uid'], $user['username'], $pms_message,$user['utype']);
            //sms
            if ($sms['set_payment'] == "1" && $amount > 0) {
                $sendSms['mobile'] = $user['mobile'];
                $sendSms['tpl'] = 'set_payment';
                $sendSms['data'] = array('sitename' => C('qscms_site_name'), 'sitedomain' => C('qscms_site_domain'));
                //D('Sms')->sendSms('notice', $sendSms);
            }
            //微信
            if (C('apply.Weixin')) {
                D('Weixin/TplMsg')->set_payment($setsqlarr['uid'], $setsqlarr['oid'], $setsqlarr['description'], $setsqlarr['amount']);
            }
        }
        return $insert_id;
    }



    /**
     * 2020/12/30
     * 添加订单数据
     * @param $user           用户信息
     * @param $oid            订单号
     * @param $order_type     订单类型，详见D('Order')->order_type
     * @param $amount         总金额
     * @param $pay_amount     现金支付金额
     * @param $pay_points     积分支付数
     * @param $service_name   所购买服务名称
     * @param $payment        支付方式英文
     * @param $payment_cn     支付方式中文
     * @param $description    订单详情描述
     * @param $addtime      下单时间
     * @param $is_paid 1待支付 2已支付
     * @param $points         购买积分数
     * @param $setmeal        购买套餐/增值服务id
     * @param $payment_time   支付时间
     * @param $params         需要特殊处理的参数序列化
     * @param $notes          备注
     * @param $job_id          职位id
     * @param $rid          简历id
     */
    public function add_order_copy($user, $oid, $order_type, $amount, $pay_amount, $pay_points, $service_name, $payment, $payment_cn, $description, $addtime, $is_paid = 1, $points = 0.0, $setmeal = 0, $payment_time = 0, $params = '', $discount = '', $notes = '',$pay_gift=0.0,$gift_id=0,$job_id=0,$rid=0) {///************chm----start******       ,$pay_gift        ****/
		$uid = $user['uid'];
        $setsqlarr['oid'] = $oid;
        $setsqlarr['uid'] = $uid;
        $setsqlarr['jobs_id'] = $job_id;
        $setsqlarr['utype'] = $user['utype'];
        $setsqlarr['order_type'] = $order_type;
        if ($pay_amount > 0 && $pay_points > 0 && $pay_gift > 0) {
			$setsqlarr['pay_type'] = 7;//现金+积分+优惠券
		} elseif($pay_gift > 0 && $pay_points > 0) {
			$setsqlarr['pay_type'] = 6;//积分+优惠券
		} elseif($pay_amount > 0 && $pay_gift > 0) {
			$setsqlarr['pay_type'] = 5;//现金+优惠券
		} elseif($pay_amount > 0 && $pay_points > 0) {
			$setsqlarr['pay_type'] = 3;//现金+积分
		} elseif ($pay_amount > 0) {
			$setsqlarr['pay_type'] = 2;//现金
		} elseif ($pay_gift > 0) {
			$setsqlarr['pay_type'] = 4;//优惠券
		} elseif ($pay_points > 0) {
			$setsqlarr['pay_type'] = 1;//积分
		}
        $info=unserialize($params);
     //   var_dump($info);
        $setsqlarr['is_paid'] = $is_paid;
        $setsqlarr['amount'] = $amount;
        $setsqlarr['pay_amount'] = $pay_amount;
        $setsqlarr['pay_points'] = $pay_points;
        $setsqlarr['pay_gift'] = $pay_gift?:0;
        $setsqlarr['gift_id'] = $gift_id?:0;
		$gift_issue_info=M("GiftIssue")->where(array("id"=>$gift_id))->find();
        $gift_issue_info['gift_info']=M("Gift")->where(array("id"=>$gift_issue_info['gift_id']))->find();
		if($gift_issue_info['gift_type']==1){
			$gift_pay_name="专享优惠券";
		}elseif($gift_issue_info['gift_type']==2){
			$gift_pay_name="新用户专享券";
		}elseif($gift_issue_info['gift_type']==3){
			$gift_pay_name="活动专享券";
		}
		
        $setsqlarr['payment'] = $payment;
        $setsqlarr['payment_cn'] = $payment_cn;
        $setsqlarr['description'] = $description;
        $setsqlarr['service_name'] = $service_name;
        $setsqlarr['points'] = $points;
        $setsqlarr['setmeal'] = $setmeal;
        $setsqlarr['params'] = $params;
        $setsqlarr['notes'] = $notes;
        $setsqlarr['addtime'] = $addtime;
        $setsqlarr['payment_time'] = $payment_time;
        $setsqlarr['discount'] = $discount;
        $setsqlarr['rid']=$rid;
     //   var_dump($setsqlarr);die;
        $payment_model = D('Payment')->where(array('typename' => $payment))->find();
        if ($payment_model && $pay_amount > 0) {
            $setsqlarr['fee'] = $pay_amount * $payment_model['fee'] / 100;
        } else {
            $setsqlarr['fee'] = 0;
        }
        if (false === $this->create($setsqlarr)) return false;
        $insert_id = $this->add($setsqlarr);
        $userinfo = M('Members')->where(array('uid' => $uid))->find();
        if (false === $sms = F('sms_config')) $sms = D('SmsConfig')->config_cache();
        if ($is_paid == 1) {
            if($user['utype']==1){
                if(C('qscms_site_dir')=='/'){
                $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }else{
                $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }
            }else{
                if(C('qscms_site_dir')=='/'){
                $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }else{
                $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }
            }
            $pms_message = '订单' . $oid . '已经添加成功，付款方式为：' . $payment_cn . '，应付金额' . $pay_amount . ($pay_points > 0 ? ('(抵扣' . $pay_points . C('qscms_points_byname') . ')') : '')  . ($pay_gift > 0 ? ('('.$gift_pay_name.'抵扣' . $pay_gift. '元)') : '') .  '。<a href="' . $replac_mail['order_url'] . '" target="_blank">点击查看详情>></a>';
            //发送站内信
            D('Pms')->write_pmsnotice($user['uid'], $user['username'], $pms_message,$user['utype']);
            //sms
            if ($sms['set_order'] == "1" && $amount > 0) {
                $sendSms['mobile'] = $user['mobile'];
                $sendSms['tpl'] = 'set_order';
                $sendSms['data'] = array('sitename' => C('qscms_site_name'), 'sitedomain' => C('qscms_site_name'), 'paymenttpye' => $payment_cn, 'oid' => $oid, 'amount' => $amount . '');
                D('Sms')->sendSms('notice', $sendSms);
            }
            //微信
            if (C('apply.Weixin')) {
                D('Weixin/TplMsg')->add_order($setsqlarr['uid'], $setsqlarr['oid'], $setsqlarr['description'], $setsqlarr['amount']);
            }
        } else if ($is_paid == 2) {
            if($user['utype']==1){
                if(C('qscms_site_dir')=='/'){
                $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }else{
                $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/CompanyService/order_detail',array('id'=>$insert_id));
                }
            }else{
                if(C('qscms_site_dir')=='/'){
                $replac_mail['order_url']=rtrim(C('qscms_site_domain').C('qscms_site_dir'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }else{
                $replac_mail['order_url']=rtrim(C('qscms_site_domain'),'/').U('Home/PersonalService/order_detail',array('id'=>$insert_id));
                }
            }
            $pms_message = '订单' . $oid . '已经支付成功，付款方式为：' . $payment_cn . '，支付金额' . $pay_amount . ($pay_points > 0 ? ('(抵扣' . $pay_points . C('qscms_points_byname') . ')') : '') . ($pay_gift > 0 ? ('('.$gift_pay_name.'抵扣' . $pay_gift. '元)') : '') .  '。<a href="' . $replac_mail['order_url'] . '" target="_blank">点击查看详情>></a>';
            //发送站内信
            D('Pms')->write_pmsnotice($user['uid'], $user['username'], $pms_message,$user['utype']);
            //sms
            if ($sms['set_payment'] == "1" && $amount > 0) {
                $sendSms['mobile'] = $user['mobile'];
                $sendSms['tpl'] = 'set_payment';
                $sendSms['data'] = array('sitename' => C('qscms_site_name'), 'sitedomain' => C('qscms_site_domain'));
                D('Sms')->sendSms('notice', $sendSms);
            }
            //微信
            if (C('apply.Weixin')) {
                D('Weixin/TplMsg')->set_payment($setsqlarr['uid'], $setsqlarr['oid'], $setsqlarr['description'], $setsqlarr['amount']);
            }
        }
        return $insert_id;
    }

    /**
     * 简历置顶回调
     */
    protected function order_paid_resume_stick($order, $user) {
        $params = unserialize($order['params']);
        $setsqlarr['resume_id'] = $params['resume_id'];
        $setsqlarr['resume_uid'] = $order['uid'];
        $setsqlarr['days'] = $params['days'];
        $setsqlarr['points'] = $params['points'];
        $setsqlarr['addtime'] = time();
        $setsqlarr['endtime'] = strtotime("+{$params['days']} day");
        $uid = $order['uid'];
        $deductible = $order['pay_points'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $rst = D('PersonalServiceStickLog')->add_stick_log($setsqlarr);
        if ($rst['state'] == 1) {
            $refreshtime = D('Resume')->where(array('id' => array('eq', $setsqlarr['resume_id'])))->getfield('refreshtime');
            $stime = intval($refreshtime) + 100000000;
            D('Resume')->where(array('id' => array('eq', $setsqlarr['resume_id'])))->save(array('stick' => 1, 'stime' => $stime));
            D('ResumeSearchPrecise')->where(array('id' => array('eq', $setsqlarr['resume_id'])))->setField('stime', $stime);
            D('ResumeSearchFull')->where(array('id' => array('eq', $setsqlarr['resume_id'])))->setField('stime', $stime);
            /* 会员日志 */

            if ($deductible > 0) {
                $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
            } else {
                $log_payment = $order['payment_cn'];
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
            }
            return true;
        }
        return false;
    }

    /**
     * 醒目标签回调
     */
    protected function order_paid_resume_tag($order, $user) {
        $params = unserialize($order['params']);
        $setsqlarr['resume_id'] = $params['resume_id'];
        $setsqlarr['resume_uid'] = $order['uid'];
        $setsqlarr['days'] = $params['days'];
        $setsqlarr['points'] = $params['points'];
        $setsqlarr['tag_id'] = $params['tag_id'];
        $setsqlarr['addtime'] = time();
        $setsqlarr['endtime'] = strtotime("+{$params['days']} day");
        $uid = $order['uid'];
        $deductible = $order['pay_points'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $rst = D('PersonalServiceTagLog')->add_tag_log($setsqlarr);
        if ($rst['state'] == 1) {
            D('Resume')->where(array('id' => array('eq', $setsqlarr['resume_id'])))->setField('strong_tag', $setsqlarr['tag_id']);
            /* 会员日志 */
            if ($deductible > 0) {
                $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
            } else {
                $log_payment = $order['payment_cn'];
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
            }
            return true;
        }
        return false;
    }

    /**
     * 简历模板回调
     */
    protected function order_paid_resume_tpl($order, $user) {
        $params = unserialize($order['params']);
        $setsqlarr['tplid'] = $params['tplid'];
        $setsqlarr['uid'] = $order['uid'];
        $deductible = $order['pay_points'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($setsqlarr['uid'], 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $setsqlarr['uid'];
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $rst = D('ResumeTpl')->add_resume_tpl($setsqlarr);
        if ($rst['state'] == 1) {
            /* 会员日志 */
            if ($deductible > 0) {
                $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
            } else {
                $log_payment = $order['payment_cn'];
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
            }
            return true;
        }
        return false;
    }

    /**
     * 增值包回调 - 简历包和短信包
     */
    protected function order_paid_setmeal_increment($order, $user) {
        $uid = $order['uid'];
        $project_id = $order['setmeal'];
        $deductible = $order['pay_points'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $setmeal_increment = D('SetmealIncrement')->where(array('id' => $project_id))->find();
        if ($setmeal_increment['cat'] == 'download_resume') {
            D('MembersSetmeal')->where(array('uid' => $uid))->setInc('download_resume', $setmeal_increment['value']);
        } else if ($setmeal_increment['cat'] == 'sms') {
            D('Members')->where(array('uid' => $uid))->setInc('sms_num', $setmeal_increment['value']);
        }
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }

    /**
     * 增值包回调 - 职位推广
     */
    protected function order_paid_job_promotion($order, $user) {
        $params = unserialize($order['params']);
        $uid = $order['uid'];
        $project_id = $order['setmeal'];
        $deductible = $order['pay_points'];
        $jobs_id = $params['jobs_id'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $setmeal_increment = D('SetmealIncrement')->where(array('id' => $project_id))->find();

        // 推广操作
        $promotionsqlarr['cp_uid'] = $uid;
        $promotionsqlarr['cp_jobid'] = $jobs_id;
        $promotionsqlarr['cp_ptype'] = $setmeal_increment['cat'];
        $promotionsqlarr['cp_days'] = $setmeal_increment['value'];
        $promotionsqlarr['cp_starttime'] = time();
        $promotionsqlarr['cp_endtime'] = strtotime("{$setmeal_increment['value']} day");
        D('Promotion')->add_promotion($promotionsqlarr);
        D('Promotion')->set_job_promotion($jobs_id, $setmeal_increment['cat']);
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
             write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }

    /**
     * 增值包回调 - 企业模板
     */
    protected function order_paid_company_tpl($order, $user) {
        $uid = $order['uid'];
        $project_id = $order['setmeal'];
        $deductible = $order['pay_points'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        D('CompanyTpl')->add_company_tpl(array('uid' => $uid, 'tplid' => $project_id));
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }

    /**
     * 增值包回调 - 诚聘通
     */
    protected function order_paid_famous_company($order, $user) {
        $uid = $order['uid'];
        D('CompanyProfile')->where(array('uid' => $uid))->setField('famous', 1);
        D('Jobs')->jobs_setfield(array('uid' => $uid), array('famous' => 1));
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
             write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        $companyinfo = D('CompanyProfile')->where(array('uid' => $uid))->find();
        $auditsqlarr['company_id'] = $companyinfo['id'];
        $auditsqlarr['reason'] = '成为诚聘通企业';
        $auditsqlarr['status'] = '是';
        $auditsqlarr['addtime'] = time();
        $auditsqlarr['audit_man'] = '系统';
        $auditsqlarr['famous'] = 1;
        M('AuditReason')->data($auditsqlarr)->add();
        return true;
    }

    /**
     * 增值包回调 - 预约刷新职位
     */
    protected function order_paid_auto_refresh_jobs($order, $user) {
        $params = unserialize($order['params']);
        $uid = $order['uid'];
        $project_id = $order['setmeal'];
        $deductible = $order['pay_points'];
        $jobs_id = $params['jobs_id'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $setmeal_increment = D('SetmealIncrement')->where(array('id' => $project_id))->find();
        $days = $setmeal_increment['value'];
        $nowtime = time();
        for ($i = 0; $i < $days * 4; $i++) {
            $timespace = 3600 * 6 * $i;
            M('QueueAutoRefresh')->add(array('uid' => $uid, 'pid' => $jobs_id, 'type' => 1, 'refreshtime' => $nowtime + $timespace));
        }
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }

    /**
     * 单独购买职位刷新
     */
    protected function order_paid_single_refresh_jobs($order, $user) {
        $params = unserialize($order['params']);
        $uid = $order['uid'];
        $deductible = $order['pay_points'];
        $jobs_id = $params['jobs_id'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        // 刷新操作
        $time = time();
        $where = array('uid' => $uid, 'id' => array('in', $jobs_id));
        $jobs = M('Jobs')->field('id,stick')->where($where)->select();
        $jobsTmp = M('JobsTmp')->field('id,stick')->where($where)->select();
        $jobs = $jobs ?: array();
        $jobsTmp = $jobsTmp ?: array();
        $jobs = array_merge($jobs, $jobsTmp);
        foreach ($jobs as $val) {
            if ($val['stick']) {
                $ids[] = $val['id'];
            } else {
                $idsTmp[] = $val['id'];
            }
        }
        if ($ids) {
            $where = array('id' => array('in', $ids));
            $stick_data = array('refreshtime' => $time, 'stime' => $time + 100000000);
            if (false === M('Jobs')->where($where)->save($stick_data)) return false;
            if (false === M('JobsTmp')->where($where)->save($stick_data)) return false;
            if (false === M('JobsSearch')->where($where)->save($stick_data)) return false;
            if (false === M('JobsSearchKey')->where($where)->save($stick_data)) return false;
        }
        if ($idsTmp) {
            $where = array('id' => array('in', $idsTmp));
            $stick_data = array('refreshtime' => $time, 'stime' => $time);
            if (false === M('Jobs')->where($where)->save($stick_data)) return false;
            if (false === M('JobsTmp')->where($where)->save($stick_data)) return false;
            if (false === M('JobsSearch')->where($where)->save($stick_data)) return false;
            if (false === M('JobsSearchKey')->where($where)->save($stick_data)) return false;
        }
        M('CompanyProfile')->where(array('uid' => $uid))->setfield('refreshtime', $time);

        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }

    /**
     * 单独购买简历下载
     */
    protected function order_paid_single_resume_download($order, $user) {
        $params = unserialize($order['params']);
        $uid = $order['uid'];
        $deductible = $order['pay_points'];
        $resume_id = $params['resume_id'];
        if ($deductible > 0) {
            $p_rst = D('MembersPoints')->report_deal($uid, 2, $deductible);
            if ($p_rst) {
                $handsel['uid'] = $uid;
                $handsel['htype'] = '';
                $handsel['htype_cn'] = $order['service_name'];
                $handsel['operate'] = 2;
                $handsel['points'] = $deductible;
                $handsel['addtime'] = time();
                D('MembersHandsel')->members_handsel_add($handsel);
            }
        }
        $resume_arr = D('Resume')->where(array('id' => array('in', $resume_id)))->select();
        foreach ($resume_arr as $key => $value) {
            $addarr['resume_id'] = $value['id'];
            if ($value['display_name'] == "2") {
                $addarr['resume_name'] = "N" . str_pad($value['id'], 7, "0", STR_PAD_LEFT);
            } elseif ($value['display_name'] == "3") {
                if ($value['sex'] == 1) {
                    $addarr['resume_name'] = cut_str($value['fullname'], 1, 0, "先生");
                } elseif ($value['sex'] == 2) {
                    $addarr['resume_name'] = cut_str($value['fullname'], 1, 0, "女士");
                }
            } else {
                $addarr['resume_name'] = $value['fullname'];
            }
            $company = M('CompanyProfile')->where(array('uid' => $uid))->find();
            $addarr["company_uid"] = $uid;
            $addarr["resume_uid"] = $value['uid'];
            $addarr['company_name'] = $company['companyname'];
            $addarr['down_addtime'] = time();
            D('CompanyDownResume')->save_down_resume($addarr);
        }
        /* 会员日志 */
        if ($deductible > 0) {
            $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
            write_members_log($user,'points',C('qscms_points_byname').'抵扣,开通服务：'.$order['service_name'],false,array('order_id'=>$order['id']));
        } else {
            $log_payment = $order['payment_cn'];
            write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
        }
        return true;
    }
    public function check_fa_bu_ids($old_jobs_infos=[],$new_jobs_info=[])
    {
//        $a1=array(23,43,67,34,64);//新
//        $a2=array(43,23,1,2,67);//老
        $result=array_diff(explode(',',$new_jobs_info),explode(',',$old_jobs_infos));
        $count=count($result);

        //验证职位名称
        $data['city_count']=$count;
        $data['is_edit']=1;
        $data['is_shou']=0;
        if($old_jobs_infos['jobs_name']!=$new_jobs_info['jobs_name']){
            $data['is_edit']=1;
            $data['is_shou']=1;
        }
        if($old_jobs_infos['nature']!=$new_jobs_info['nature']){
            $data['is_edit']=1;
            $data['is_shou']=1;
        }
        if($count>0){
            $data['is_edit']=1;
            $data['is_shou']=1;
        }

        return $data;
    }
        protected function edit_fa_count($jobs_info,$user)
    {
        if($jobs_info['is_edit']){
            if($jobs_info['is_shou']){
                $old_jobs_infos=S('jobs_info');
                $new_jobs_info=$jobs_info;
                //判断是否修改了职位名称
                //判断是否修改i工程类别
                $check_info=$this->check_fa_bu_ids($old_jobs_infos['fa_bu_ids'],$new_jobs_info['fa_bu_ids']);
                $count=$check_info['city_count'];
              // var_dump($check_info);die;
                if($jobs_info['old_zhao_type_id']==1){   //常规
                    M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('cg_yi_fa_count',$count);
                }elseif ($jobs_info['old_zhao_type_id']==2){//急招
                    M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('ji_zhao_yi_fa_count',$count);
                }elseif ($jobs_info['old_zhao_type_id']==3){//短期
                    M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('duan_qi_yi_fa_count',$count);
                }elseif ($jobs_info['old_zhao_type_id']==4){//项目
                    M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('xmzc_yi_fa_count',$count);
                }
            }
        }else{
            $city_ids=explode(',',$jobs_info['fa_bu_ids']);
            $count=count($city_ids);
           // var_dump($count);
            if($jobs_info['old_zhao_type_id']==1){   //常规
                M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('cg_yi_fa_count',$count);
            }elseif ($jobs_info['old_zhao_type_id']==2){//急招
                M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('ji_zhao_yi_fa_count',$count);
            }elseif ($jobs_info['old_zhao_type_id']==3){//短期
                M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('duan_qi_yi_fa_count',$count);
            }elseif ($jobs_info['old_zhao_type_id']==4){//项目
                M('members_settaocan')->where(['uid'=>$user['uid']])->setInc('xmzc_yi_fa_count',$count);
            }
           //var_dump( M('members_settaocan')->getLastSql());
          //  die;
        }
    }
    /*
        付款后开通
    */
    public function order_paid($out_trade_no, $time) {
        $order = $this->where(array('oid' => $out_trade_no, 'is_paid' => '1'))->find();		
		if($order['gift_id']){
			$gift_issue_info=M("GiftIssue")->where(array("id"=>$order['gift_id']))->find();
			$gift_issue_info['gift_info']=M("Gift")->where(array("id"=>$gift_issue_info['gift_id']))->find();
			if($gift_issue_info['gift_type']==1){
				$gift_pay_name="专享优惠券";
			}elseif($gift_issue_info['gift_type']==2){
				$gift_pay_name="新用户专享券";
			}elseif($gift_issue_info['gift_type']==3){
				$gift_pay_name="活动专享券";
			}
		}
		//var_dump($order);die;
        //判断是否支付完成（防止支付完立即关闭页面  从而导致未开通服务）
        if (intval($order['is_paid']) == 1) {
            $data['is_paid'] = 2;
            $data['payment_time'] = $time;
            $this->where(array('oid' => $out_trade_no))->save($data);
            D('CompanyProfile')->where(array('uid'=>$order['uid']))->setField('order_paid',1);
            $user = D('Members')->get_user_one(array('uid' => $order['uid']));
            //套餐支付
            if ($order['order_type'] == '1') {
                $deductible = $order['pay_points'];
                if ($deductible > 0) {
                    $p_rst = D('MembersPoints')->report_deal($order['uid'], 2, $deductible);
                    if ($p_rst) {
                        $handsel['uid'] = $order['uid'];
                        $handsel['htype'] = '';
                        $handsel['htype_cn'] = $order['service_name'];
                        $handsel['operate'] = 2;
                        $handsel['points'] = $deductible;
                        $handsel['addtime'] = time();

                        D('MembersHandsel')->members_handsel_add($handsel);
                    }
                }
                $order_name = "套餐订单";
                //D('MembersSetmeal')->set_members_setmeal($order['uid'], $order['setmeal']);/*chm修改前*/
//                D('MembersSetmeal')->set_members_setmeal($order['uid'], $order['setmeal'], $order['pay_amount']);/*chm修改后*/
//                $setmeal = M('Setmeal')->where(array('id' => $order['setmeal']))->find();
                //2020/12/26 10：03 修改套餐
                D('MembersSettaocan')->set_members_setmeal($order['uid'], $order['setmeal'], $order['pay_amount']);/*chm修改后*/
                $setmeal = M('Settaocan')->where(array('id' => $order['setmeal']))->find();

                /* 会员日志 */
                if ($deductible > 0) {
                    $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                } else {
                    $log_payment = $order['payment_cn'];
                }
                //推荐该企业  顾问的分成
                add_guwen_tui_com_give_money_log($order['uid'],'buy_taocan',$order['id']);

                if($order['payment']=='wxpay'){
                    JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'wxpay','购买套餐',date('Y-m-d H:i:s',$order['payment_time']),'buy_taocan');
                }elseif ($order['payment']=='remittance'){
                    JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'remittance','购买套餐',date('Y-m-d H:i:s',$order['payment_time']),'buy_taocan');
                }
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
                //会员套餐变更记录。会员购买成功。log_type 2表示：会员自己购买
                $notes = date('Y-m-d H:i', time()) . "通过：" . D('Payment')->get_payment_info($order['payment_name'], true) . " 成功充值 " . $order['amount'] . "元并开通{$setmeal['setmeal_name']}";
                write_members_log($user,'settaocan',$notes);
                add_member_log($user['uid'],'taocan','buy_taocan',$order['amount'],0,'购买套餐'.$setmeal['setmeal_name'],0,$setmeal['settaocan_id']);//套餐购买记录

                add_member_log($user['uid'],'wxpay','buy_taocan',$order['amount'],0,'购买套餐'.$setmeal['setmeal_name'],0,$setmeal['settaocan_id']);//套餐购买记录
            } //积分支付
            else if ($order['order_type'] == '2') {
                $order_name = C('qscms_points_byname') . "订单";
                $p_rst = D('MembersPoints')->report_deal($user['uid'], 1, $order['points']);
                if ($p_rst) {
                    $handsel['uid'] = $user['uid'];
                    $handsel['htype'] = 'buy_points';
                    $handsel['htype_cn'] = '充值' . C('qscms_points_byname');
                    $handsel['operate'] = 1;
                    $handsel['points'] = $order['points'];
                    $handsel['addtime'] = time();
                    D('MembersHandsel')->members_handsel_add($handsel);
                }
                $user_points = D('MembersPoints')->get_user_points($user['uid']);
                /* 会员日志 */
                $notes = date('Y-m-d H:i', time()) . "通过：" . D('Payment')->get_payment_info($order['payment_name'], true) . " 成功充值 " . $order['points'].C('qscms_points_byname');
                write_members_log($user, 'order', $notes, false, array('order_id' => $order['id']));
            }
            //简历置顶
            if ($order['order_type'] == '3') {
                $this->order_paid_resume_stick($order, $user);
            } //醒目标签
            else if ($order['order_type'] == '4') {
                $this->order_paid_resume_tag($order, $user);
            } //简历模板
            else if ($order['order_type'] == '5') {
                $this->order_paid_resume_tpl($order, $user);
            } //增值包-简历包,短信包
            else if ($order['order_type'] == '6' || $order['order_type'] == '7') {
                $this->order_paid_setmeal_increment($order, $user);
            } //增值包-职位推广
            else if ($order['order_type'] == '8' || $order['order_type'] == '9') {
                $this->order_paid_job_promotion($order, $user);
            } //增值包-企业模板
            else if ($order['order_type'] == '10') {
                $this->order_paid_company_tpl($order, $user);
            } //增值包-诚聘通
            else if ($order['order_type'] == '11') {
                $this->order_paid_famous_company($order, $user);
            } //增值包-预约职位刷新
            else if ($order['order_type'] == '12') {
                $this->order_paid_auto_refresh_jobs($order, $user);
            } //单独购买职位刷新
            else if ($order['order_type'] == '13') {
                $this->order_paid_single_refresh_jobs($order, $user);
            } //单独购买简历下载
            else if ($order['order_type'] == '14') {
              //  var_dump(2222);die;
                $resume = D('Resume')->get_resume_one($order['rid']);
                $rid = is_array($order['rid']) ? $order['rid'] : explode(",", $order['rid']);
                $info=unserialize($order['params']);
                $down_type=$info['down_type'];

               //  var_dump($info);
                $rid=$info['resume_id'];
                $addarr['rid'][0]=$info['resume_id'];
                $addarr['down_type']=$down_type;
//var_dump($addarr);die;
            //  var_dump( C('visitor'));die;
                $user=M('members')->where(['uid'=>$order['uid']])->find();
                $r = D('CompanyDownResume')->add_down_resume($addarr, $user);
               //  file_put_contents('down_info.txt',json_encode($r));
              //  $r = D('CompanyDownResume')->add_down_resume($addarr, C('visitor'));
  //  var_dump($r);die;
                if ($r['state'] == 1) {
                    if($order['payment']=='gcb'){
                      $taocan_info=  M('MembersSetgcb')->where(['uid' => C('visitor.uid')])->find();
                        $res = M('MembersSetgcb')->where(['uid' => C('visitor.uid')])->setInc('use_num', $order['pay_amount']);
                        //添加工程币的使用记录
                        if ($res) {
                            //增加顾问余额
                            $user_info=M('resume')->where(['id'=>$rid])->find();
                            down_resume_get_guwen_money($taocan_info,'gcb',$user_info['uid'],$down_type,$rid,$order);
                            //用户记录
                            add_member_log(C('visitor.uid'), 'gcb', 'resume_down', $order['pay_amount'], $rid[0], '【' . $resume['fullname'] . '】' . '简历下载');
                        }
                    }elseif ($order['payment']=='use_taocan'){
                       //使用套餐扣除次数
                        //增加顾问余额
                        $taocan_info=  M('MembersSettaocan')->where(['uid' => C('visitor.uid')])->find();
                        $user_info=M('resume')->where(['id'=>$rid])->find();
                        $count = D('CompanyDownResume')->get_down_count($order['uid']);
                       if ($count > 3) {
                            down_resume_get_guwen_money($taocan_info,'use_taocan',$user_info['uid'],$down_type,$rid,$order);
                        }
                        //用户记录
                        add_member_log(C('visitor.uid'), 'taocan', 'resume_down', $order['pay_amount'], $rid[0], '【' . $resume['fullname'] . '】' . '简历下载');
                    }elseif ($order['payment']=='remittance'){
                        //线下转账
                        //增加顾问余额
                        $user_info=M('resume')->where(['id'=>$rid])->find();
                        JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'remittance','下载简历',date('Y-m-d H:i:s',$order['payment_time']),'down_resume');
                        down_resume_get_guwen_money([],'remittance',$user_info['uid'],$down_type,$rid,$order);
                        //用户记录
                        add_member_log(C('visitor.uid'), 'remittance', 'resume_down', $order['pay_amount'], $rid[0], '【' . $resume['fullname'] . '】' . '简历下载');
                    }elseif($order['payment']=='wxpay'){
                        //微信支付
                        //增加顾问余额

                        JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'wxpay','下载简历',date('Y-m-d H:i:s',$order['payment_time']),'down_resume');

                        $user_info=M('resume')->where(['id'=>$rid])->find();
                        down_resume_get_guwen_money([],'wxpay',$user_info['uid'],$down_type,$rid,$order);
                        //用户记录
                        add_member_log(C('visitor.uid'), 'wxpay', 'resume_down', $order['pay_amount'], $rid[0], '【' . $resume['fullname'] . '】' . '简历下载');
                        $ids=M('gu_wen_jie_dan_order')->join('as g left join qs_guwen_tui_jian_rusume as gt on g.id=gt.order_id and gt.resume_uid ='.$user_info['uid'])->where(['g.order_status'=>6])->getField('g.id,gt.order_id',true);
                        if($ids){
                        M('gu_wen_jie_dan_order')->where(['id'=>['in',$ids]])->setField('order_status',2);
                        }
                    }
                   //todo 下载支付成功   增加顾问的余额
                    //下载简历修改订单状态
                    $user_info=M('resume')->where(['id'=>$rid])->find();
                    $ids=M('gu_wen_jie_dan_order')->join('as g left join qs_guwen_tui_jian_rusume as gt on g.id=gt.order_id and gt.resume_uid ='.$user_info['uid'])->where(['g.order_status'=>['in',[6,7]]])->getField('g.id,gt.order_id',true);
                    if($ids){
                         M('gu_wen_jie_dan_order')->where(['id'=>['in',$ids]])->setField('order_status',2);
                    }
                } else {
                    D('Order')->where(array('id' => $order['id']))->delete();
                  return $r;
                }
               // $this->order_paid_single_resume_download($order, $user);//之前的下载简历方法
            }
            //购买工程币   2020/12/26 11：52
            else if ($order['order_type'] == '15') {
                $deductible = $order['pay_points'];
                if ($deductible > 0) {
                    $p_rst = D('MembersPoints')->report_deal($order['uid'], 2, $deductible);
                    if ($p_rst) {
                        $handsel['uid'] = $order['uid'];
                        $handsel['htype'] = '';
                        $handsel['htype_cn'] = $order['service_name'];
                        $handsel['operate'] = 2;
                        $handsel['points'] = $deductible;
                        $handsel['addtime'] = time();
                        D('MembersHandsel')->members_handsel_add($handsel);
                    }
                }
                $order_name = "套餐订单";
                //D('MembersSetmeal')->set_members_setmeal($order['uid'], $order['setmeal']);/*chm修改前*/
//                D('MembersSetmeal')->set_members_setmeal($order['uid'], $order['setmeal'], $order['pay_amount']);/*chm修改后*/
//                $setmeal = M('Setmeal')->where(array('id' => $order['setmeal']))->find();
                //2020/12/26 10：03 修改套餐
                D('MembersSetgcb')->set_members_setmeal($order['uid'], $order['setmeal'], $order['pay_amount']);/*chm修改后*/
                $setmeal = M('Setgcb')->where(array('id' => $order['setmeal']))->find();

                JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'wxpay','购买工程币',date('Y-m-d H:i:s',$order['payment_time']),'buy_gcb');

                //推荐该企业  顾问的分成
                add_guwen_tui_com_give_money_log($order['uid'],'buy_gcb',$order['id']);

                /* 会员日志 */
                if ($deductible > 0) {
                    $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                } else {
                    $log_payment = $order['payment_cn'];
                }
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
                //会员套餐变更记录。会员购买成功。log_type 2表示：会员自己购买
                $notes = date('Y-m-d H:i', time()) . "通过：" . D('Payment')->get_payment_info($order['payment_name'], true) . " 成功充值 " . $order['amount'] . "元并开通{$setmeal['setmeal_name']}";
                write_members_log($user,'setgcb',$notes);

           //     if($order[''])


                add_member_log($user['uid'],'gcb','buy_gcb',$setmeal['send_num']+$setmeal['num'],0,'购买增加工程币'.$setmeal['setmeal_name'],0,$setmeal['settaocan_id']);
                add_member_log($user['uid'],'wxpay','buy_gcb',$order['amount'],0,'购买工程币'.$setmeal['setmeal_name'],0,$setmeal['settaocan_id']);//套餐购买记录
            }
            //发布职位  2020/12/30 15：34
            else if ($order['order_type'] == '16') {
                $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                //修改职位结束时间
                edit_zhao_end_time($jobs_info['zhao_end_time'],$order);
                 //悬赏 顾问找  订单修改审核状态
                if(in_array($order['fa_type'],[1,2,3])){
                $setsqlarr=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                $setsqlarr['topclass']=explode(',',$setsqlarr['topclass']);
                $setsqlarr['category']=explode(',',$setsqlarr['category']);
                $city_info=explode('.',$setsqlarr['district']);
                $setsqlarr['district']=$city_info[2];
                $setsqlarr['audit']=1;
                $rst = D('Jobs')->edit_jobs($setsqlarr, C('visitor'),false);
               // var_dump($rst);die;
                }
                D('Order')->where(array('id' => $order['uid']))->save([
                    'all_total'=>['exp','all_total+'.$order['pay_amount']],
                ]);
                $deductible = $order['pay_points'];
                if ($deductible > 0) {
                    $p_rst = D('MembersPoints')->report_deal($order['uid'], 2, $deductible);
                    if ($p_rst) {
                        $handsel['uid'] = $order['uid'];
                        $handsel['htype'] = '';
                        $handsel['htype_cn'] = $order['service_name'];
                        $handsel['operate'] = 2;
                        $handsel['points'] = $deductible;
                        $handsel['addtime'] = time();
                        D('MembersHandsel')->members_handsel_add($handsel);
                    }
                }
                $order_name = "发布职位";
                $setmeal = M('Setgcb')->where(array('id' => $order['setmeal']))->find();
                /* 会员日志 */
                if ($deductible > 0) {
                    $log_payment = $order['payment_cn'] . '+' . C('qscms_points_byname') . '抵扣';
                } else {
                    $log_payment = $order['payment_cn'];
                }
                write_members_log($user, 'order', '开通服务：' . $order['service_name'], false, array('order_id' => $order['id']));
                //会员套餐变更记录。会员购买成功。log_type 2表示：会员自己购买
                $notes = date('Y-m-d H:i', time()) . "通过：" . D('Payment')->get_payment_info($order['payment_name'], true) . " 成功充值 " . $order['amount'] . "元并开通{$setmeal['setmeal_name']}";
             if($order['payment']=='gcb'){
                 //查询是否存在 发布记录  和支付 保证金记录
                 $row=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'gcb','order_type'=>'fa_bu'])->find();
                 $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                 if($row){
                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'gcb','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'gcb','guwen_server',$order['amount'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 }else{
                     if(($order['amount']-$order['service_money'])>0){
                         //没有使用套餐
                         add_member_log($user['uid'],'gcb','fa_bu',$order['amount']-$order['service_money'],0,'发布职位'.$order['service_name'],$order['jobs_id']);

                     }else{
                         $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                         $this->edit_fa_count($jobs_info,$user);//修改发布次数
                         add_member_log($user['uid'],'taocan','fa_bu',$order['amount']-$order['service_money'],0,'发布职位'.$order['service_name'],$order['jobs_id']);

                     }
                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'gcb','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'gcb','guwen_server',$order['service_money'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 }

//                 add_member_log($user['uid'],'gcb','fa_bu',$order['amount'],0,'发布职位'.$order['service_name'],$order['jobs_id']);
             }elseif ($order['payment']=='use_taocan'){
                 //减少发布次数
                 $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                 //查询城市数量
                  $this->edit_fa_count($jobs_info,$user);//修改发布次数
                 add_member_log($user['uid'],'taocan','fa_bu',$order['amount'],0,'发布职位'.$order['service_name'],$order['jobs_id']);
             }elseif ($order['payment']=='remittance'){
                 //查询是否存在 发布记录  和支付 保证金记录
                 $row=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'remittance','order_type'=>'fa_bu'])->find();
                 $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                 if($row){
                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'remittance','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'remittance','guwen_server',$order['amount']-$order['service_money'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 }else{
                     if(($order['amount']-$order['service_money'])>0){
                         //没有使用套餐
                         add_member_log($user['uid'],'remittance','fa_bu',$order['amount'],0,'发布职位'.$order['service_name'],$order['jobs_id']);
                     }else{
                         $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                         $this->edit_fa_count($jobs_info,$user);//修改发布次数
                         add_member_log($user['uid'],'taocan','fa_bu',$order['amount'],0,'发布职位'.$order['service_name'],$order['jobs_id']);
                     }

                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'remittance','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'remittance','guwen_server',$order['amount'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 }
             }
             else{
                 //推荐该企业  顾问的分成
               //  add_guwen_tui_com_give_money_log($order['uid'],'buy_taocan',$order['id']);
       // var_dump($order);
                 $row=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'wxpay','order_type'=>'fa_bu'])->find();
          //  var_dump(M('member_use_log')->getLastSql());
           //   var_dump($row);die;
                 if($row){
                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'wxpay','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'wxpay','guwen_server',$order['service_money'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 }else{
                     if($order['amount']-$order['service_money']>0){
                         //没有使用套餐
                         add_member_log($user['uid'],'wxpay','fa_bu',$order['amount']-$order['service_money'],0,'发布职位'.$order['service_name'],$order['jobs_id']);

                     }else{
                         $jobs_info=M('jobs')->where(['id'=>$order['jobs_id']])->find();
                         $this->edit_fa_count($jobs_info,$user);//修改发布次数
                         add_member_log($user['uid'],'taocan','fa_bu',$order['amount']-$order['service_money'],0,'发布职位'.$order['service_name'],$order['jobs_id']);

                     }
                     $row_ser=M('member_use_log')->where(['job_id'=>$order['jobs_id'],'use_type'=>'wxpay','order_type'=>'guwen_server'])->find();
                     if($order['service_money']>0 && !$row_ser){
                         add_member_log($user['uid'],'wxpay','guwen_server',$order['service_money'],0,'发布职位'.$order['service_name'].'保证金',$order['jobs_id']);
                     }
                 //    var_dump(222);die;
                     JobsInfoModel::add_user_pay_log($order['uid'],$order['id'],$order['oid'],$order['pay_amount'],'wxpay','发布职位',date('Y-m-d H:i:s',$order['payment_time']),'fa_bu');

                 }
             //    add_member_log($user['uid'],'wxpay','fa_bu',$order['amount'],0,'发布职位'.$order['service_name'],$order['jobs_id']);
             }
//                add_member_log($user['uid'],'wxpay','buy',$order['amount'],0,'购买工程币'.$setmeal['setmeal_name'],0);//套餐购买记录
            }
            //申请成为人才顾问支付  求职变更人才顾问
            else if ($order['order_type'] == '17') {
                $guwenLevel = M('GuwenLevel')->where(['level'=>2])->find();
                //$guwenLevel = M("QuestionnaireUserList")->where(['uid'=> $order['uid'],'status'=>1])->find();
                $guwenData   = ['gw_uid'=> $order['uid'], 'shou_quan_time'=> $time, 'has_date'=> date('Y', $time), 'level'=>$guwenLevel['level'], 'level_name'=>$guwenLevel['name']];
                M("GuwenLevelLog")->add($guwenData);

                //修改用户类型
                M('members')->where(['uid'=> $order['uid']])->save(['utype'=>3, 'advisor_level'=>$guwenLevel['level'], 'advisor_level_name'=>$guwenLevel['name']]);
                M('ResumeSearchFull')->where(['uid'=> $order['uid']])->save(['utype'=>3]);
                M('ResumeSearchPrecise')->where(['uid'=> $order['uid']])->save(['utype'=>3]);

                //申请成为顾问则删除顾问人才库
                $gwids  = M("GuwenUser")->where(['uid'=>$order['uid']])->getField('guwen_id');
                M("GuwenUser")->where(['uid'=>$order['uid']])->delete();
                if(!empty($gwids)) {
                    M("Members")->where(['uid' => ['in', $gwids]])->setDec('user_count');//顾问人才数量减1
                }

                //成为人才顾问删除相关企业资料
                M('CompanyProfile')->where(['uid'=>$order['uid']])->delete();
                M('companyImg')->where(['uid'=>$order['uid']])->delete();//图片

                add_member_log($user['uid'],'wxpay','biangengrencaiguwen',$order['amount'],$order['rid'],'顾问等级记录添加：'.$order['service_name'],$order['jobs_id']);
            }
            //简历投递
            else if ($order['order_type'] == '18') {
                $order['params']    = unserialize($order['params']);
                $reg = D('PersonalJobsApply')->jobs_apply_add($order['params']['jid'], $user, $order['params']['resume_id']);
                send_email_by_jobsapplay($order['params']['jid'],$order['params']['resume_id']);
                add_member_log($user['uid'],'wxpay','jianlitoudi',$order['amount'],$order['rid'],'简历下载：'.$order['service_name'],$order['jobs_id']);
            }

            //站内信
            if ($user['utype'] == 1) {
                $replac_mail['order_url'] = rtrim(C('qscms_site_domain') . C('qscms_site_dir'), '/') . U('Home/CompanyService/order_detail', array('id' => $order['id']));
            } else {
                $replac_mail['order_url'] = rtrim(C('qscms_site_domain') . C('qscms_site_dir'), '/') . U('Home/PersonalService/order_detail', array('id' => $order['id']));
            }
            $pms_message = '订单' . $order['oid'] . '已经支付成功，付款方式为：' . $order['payment_cn'] . '，支付金额' . $order['pay_amount'] . ($order['pay_points'] > 0 ? ('(抵扣' . $order['pay_points'] . C('qscms_points_byname') . ')') : '')  . ($order['pay_gift'] > 0 ? ('('.$gift_pay_name.'抵扣' .$order['pay_gift']. '元)') : ''). '。<a href="' . $replac_mail['order_url'] . '" target="_blank">点击查看详情>></a>';
            D('Pms')->write_pmsnotice($user['uid'], $user['username'], $pms_message,$order['utype']);
            // 发送短信
            if (false === $sms = F('sms_config')) $sms = D('SmsConfig')->config_cache();
            if ($sms['set_payment'] == 1 && $order['amount'] > 0) {
                $sendSms['mobile'] = $user['mobile'];
                $sendSms['tpl'] = 'set_payment';
                $sendSms['data'] = array('sitename' => C('qscms_site_name'), 'sitedomain' => C('qscms_site_domain'));
                D('Sms')->sendSms('notice', $sendSms);
            }
            //微信
            if (C('apply.Weixin')) {
                D('Weixin/TplMsg')->set_payment($order['uid'], $order['oid'], $order['description'], $order['amount']);
            }
            return true;
        } else {
            return true;
        }
    }

    /*
        订单列表
        @$data 订单查询条件
    */
    public function get_order_list($data, $pagesize = 10) {
        $count = $this->where($data)->count();
        $pager = pager($count, $pagesize);
        $rst['list'] = $this->where($data)->order('id desc')->limit($pager->firstRow . ',' . $pager->listRows)->select();
        foreach ($rst['list'] as $key => $value) {
            $rst['list'][$key]['invoice'] = D('OrderInvoice')->getone($value['id']);
        }
        $rst['page'] = $pager->fshow();
        $rst['page_params'] = $pager->get_page_params();
        return $rst;
    }

    /*
    订单列表
    @$data 订单查询条件
*/
    public function get_order_list_api($data,$page=1, $pagesize = 10) {
        $count = $this->where($data)->count();
        $pager = pager($count, $pagesize);
        $rst['list'] = $this->field('id,pay_amount,description,addtime')->where($data)->order('id desc')->page($page,$pagesize)->select();
        foreach ($rst['list'] as $key => $value) {
            $rst['list'][$key]['invoice'] = D('OrderInvoice')->getone($value['id']);
            $rst['list'][$key]['addtime'] =date('Y-m-d H:i:s',$value['addtime']);
        }
        $rst['page'] = $pager->fshow();
        $rst['page_params'] = $pager->get_page_params();
        return $rst;
    }

    /**
     * 付款后开通
     */
    function admin_order_paid($id) {
        $time = time();
        $order = $this->where(array('id' => $id))->find();
        return $this->order_paid($order['oid'], $time);
    }

    /**
     * 录用回调
     * @param $oid
     * @param $time
     * @return bool|void
     */

    public function guwen_zhutui_luyong_orderpaid($oid,$time)
    {
       // $oid='GRZ-210205-173351';
        $order = M('lu_yong_pay_order')->where(array('oid' => $oid, 'pay_status' => 0))->find();
       // var_dump($order);die;;
        if($order['pay_status']==0){
            $data['pay_status'] = 1;
            $data['pay_time'] = $time;
            $re= M('lu_yong_pay_order')->where(['oid'=>$oid])->save($data);
            $info=M('resume')->where(['uid'=>$order['uid']])->getField('fullname');
          //  var_dump($order);die;;
            if($order['payment']=='gcb'){
                $res = M('MembersSetgcb')->where(['uid' => C('visitor.uid')])->setInc('use_num', $order['pay_money']);
                //添加工程币的使用记录
                if ($res) {
                    add_member_log($order['comp_uid'],'gcb','guwen_server',$order['pay_money'],0,'录用用户'.$info.'支付',$order['jobs_id']);
                }
            }elseif ($order['payment']=='wxpay'){
                add_member_log($order['comp_uid'],'wxpay','guwen_server',$order['pay_money'],0,'录用用户'.$info.'支付',$order['jobs_id']);
            }elseif ($order['payment']=='remittance'){
                add_member_log($order['comp_uid'],'remittance','guwen_server',$order['pay_money'],0,'录用用户'.$info.'支付',$order['jobs_id']);
            }
            $order_info=M('guwen_tui_jian_rusume')->where(['resume_uid'=>$order['uid'],'order_id'=>$order['jie_order_id'],'jobs_id'=>$order['jobs_id']])->find();
            if($order['ruzhi_time']){
                $re=  M('guwen_tui_jian_rusume')->where(['id'=>$order_info['id']])->save([
                    'tui_status'=>$order['tui_status'],
                    'up_time'=>date('Y-m-d H:i:s',time()),
                    'ruzhi_time'=>$order['ruzhi_time'],
                ]);
            }else{
                $re=  M('guwen_tui_jian_rusume')->where(['id'=>$order_info['id']])->save([
                    'tui_status'=>$order['tui_status'],
                    'up_time'=>date('Y-m-d H:i:s',time()),
                //    'ruzhi_time'=>$order['ruzhi_time'],
                ]);
            }
           // if($order['tui_status']==1){
                $count= M('lu_yong_pay_order')->where(['jie_order_id'=>$order['jie_order_id'],'uid'=>$order['uid'],
                    'comp_uid'=>$order['comp_uid'],'pay_status'=>1,'tui_status'=>$order['tui_status'],'jobs_id'=>$order['jobs_id']])->count();
          //  }
            if($count>1){
                return;
            }

            M('gu_wen_jie_dan_order')->where(['id'=>$order_info['order_id']])->setField('order_status',3);
            //todo  顾问分佣
            $jobs_info=M('jobs')->where(['id'=>$order_info['jobs_id']])->find();
            $desc='推荐的人才';
            if($order['tui_status']==1){//入职
                //增加顾问余额记录
                $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,1,$order_info['server_money'],$order_info['xishu_rate']);
           //  var_dump($money_info);die;
                add_guwen_money($order_info['guwen_uid'],$money_info['give_money'],$desc,'service',1,0,4,0,$order_info['jobs_id'],$order_info['order_id'],'入职收入顾问服务费'.$money_info['give_money'],$order_info['comp_uid'],$money_info['all_money'],1,1,$order['uid']);
            }
            if($order['tui_status']==4){  //入职满月
                //增加顾问余额记录
                $money_info=get_job_in_money($order_info['guwen_uid'],$jobs_info,1,$order_info['server_money'],$order_info['xishu_rate']);
                add_guwen_money($order_info['guwen_uid'],$money_info['give_money'],$desc,'service',1,0,4,0,$order_info['jobs_id'],$order_info['order_id'],'入职满月收入顾问服务费'.$money_info['give_money'],$order_info['comp_uid'],$money_info['all_money'],1,2,$order['uid']);
            }
            return $re;
        }
           return true;
    }

    /**
     * 补交支付
     * @param $oid
     * @param $time
     * @return bool|void
     */

    public function com_bu_jiao_orderpaid($oid,$time=NOW_TIME)
    {
        // $oid='GRZ-210205-173351';
        $order = M('com_bu_jiao_order')->where(array('oid' => $oid, 'pay_status' => 0))->find();
//       var_dump($order);
//        var_dump($order['pay_status']==0);die;;
        if($order && $order['pay_status']==0){
            $data['pay_status'] = 1;
            $data['pay_time'] = $time;
            $re= M('com_bu_jiao_order')->where(['oid'=>$oid])->save($data);
           // $info=M('resume')->where(['uid'=>$order['uid']])->getField('fullname');
            //  var_dump($order);die;;
            if($order['payment']=='gcb'){
                $res = M('MembersSetgcb')->where(['uid' => C('visitor.uid')])->setInc('use_num', $order['pay_money']);
                //添加工程币的使用记录
                if ($res) {
                    add_member_log($order['uid'],'gcb','bu_jiao',$order['pay_money'],0,'补交支付',$order['jobs_id']);
                }
            }elseif ($order['payment']=='wxpay'){
                add_member_log($order['comp_uid'],'wxpay','bu_jiao',$order['pay_money'],0,'补交支付',$order['jobs_id']);
            }elseif ($order['payment']=='remittance'){
                add_member_log($order['comp_uid'],'remittance','bu_jiao',$order['pay_money'],0,'补交支付',$order['jobs_id']);
            }

           //修改 订单表里面的保证金
            $re=M('order')->where(['id'=>$order['order_id']])->setInc('service_money',$order['pay_money']);

            return $re;
        }
        return true;
    }
}

?>